--[[ 编码: JX-110-02 名称: 调度系统-输送线-任务推送 作者:HAN 日期: 2025-1-29 入口函数: Push 功能说明: 推送搬运任务到输送线 { "requestPk": "pk2022120614242376", "contNo": "60001", "contType": "D", "trkPrty": "5", "trkType": "02", "frmPos": "HW-01K010101", "toPos": "2F_OUT_ST21", "trkSt": 0, "clientCode": "wms", "reqTime": "2022-11-11 11:32:08" } 变更记录: --]] wms_task = require( "wms_task" ) wms_op = require( "wms_operation" ) function Push( strLuaDEID ) local nRet, strRetInfo, strObjJson local task -- step1: 获取需要推送的任务对象 nRet, task = m3.GetSysCurEditDataObj( strLuaDEID, "Task" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.GetSysCurEditDataObj 失败!"..task ) end -- step2: 调用NDC接口 -- 如果任务的类型 = 搬运 local strXml = '' local state_wait = wms_base.Get_nConst( strLuaDEID, "任务状态-等待" ) -- 如果任务状态 不等于 "等待" 状态就返回,不需要推送 if (task.bs_state ~= state_wait ) then return end local wcs_url nRet, wcs_url = wms_base.Get_sConst2( strLuaDEID, "WCS服务地址") if ( nRet ~= 0 ) then lua.Stop( strLuaDEID, "系统无法获取常量'WCS服务地址'") return end local trkType = "" -- 任务类型 local trkPrty = tostring( task.priority ) if ( task.type == wms_base.Get_nConst( strLuaDEID, "任务类型-输送线入库搬运" ) or task.type == wms_base.Get_nConst( strLuaDEID, "任务类型-堆垛机入库搬运" ) ) then trkType = "1" elseif ( task.type == wms_base.Get_nConst( strLuaDEID, "任务类型-输送线出库搬运" ) or task.type == wms_base.Get_nConst( strLuaDEID, "任务类型-堆垛机出库搬运" ) or task.type == wms_base.Get_nConst( strLuaDEID, "任务类型-立库出库搬运" ) ) then trkType = "2" else mobox.stopProgram( strLuaDEID, "任务类型值 = "..task.type..", 不能推送给输送线!") return end --巨沃的料箱需要给WCS传来源系统的值 local curTime = os.date("%Y-%m-%d %H:%M:%S") local strurl = wcs_url..'/wcs-admin/api/receive' local body = { requestPk = task.code, contNo = task.cntr_code, trkType = trkType, trkPrty = trkPrty, frmPos = task.start_loc_code, toPos = task.end_loc_code, clientCode = "wms", reqTime = curTime, souRce = task.source_sys --来源系统 } lua.Debug( strLuaDEID, debug.getinfo(1), "调WCS接口-->", strurl ) lua.Debug( strLuaDEID, debug.getinfo(1), "body", body ) --[[ nRet, strRetInfo = mobox.sendHttpRequest( strurl, "",lua.table2str(body) ) if ( nRet ~= 0 or strRetInfo == '' ) then lua.Error( strLuaDEID, debug.getinfo(1), "调用WCS /wcs-admin/api/receive 接口失败! "..strRetInfo ) end local ret_info = json.decode( strRetInfo ) ]] local ret_info = {} ret_info.code = "0" -- step3 设置任务状态=已推送 if ( ret_info.code == "0" ) then nRet, strRetInfo = wms_task.SetStateByCode( strLuaDEID, task.code, "任务状态-已推送" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end -- 1 表示任务已经推送到设备 nRet, strRetInfo = wms_op.SetTaskState( strLuaDEID, task.op_code, 1 ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), strRetInfo ) end local task_action = m3.AllocObject(strLuaDEID,"Task_Action") task_action.task_code = task_code task_action.action_code = 0 task_action.action = "任务推送" task_action.eq_code = "XXX" task_action.eq_type_name = "XXX" m3.CreateDataObj( strLuaDEID, task_action ) else lua.Debug( strLuaDEID, debug.getinfo(1), "调用WCS /wcs-admin/api/receive 接口失败", ret_info.msg ) end end